// @ts-ignore
import CryptoJS from 'crypto-js'

const ENCRYPT_KEY = 'GftZqNE0BVdB2kwx'

const ENCRYPT_IV = '3zyJFPEzh6rUeUNi'

export const encryptValue = (str: string) => {
    const key = CryptoJS.enc.Utf8.parse(ENCRYPT_KEY)
    const iv = CryptoJS.enc.Utf8.parse(ENCRYPT_IV)

    // 加密方式使用CBC，padding偏移量设置成Pkcs7，以便和后端对应解密
    const encryptedValue = CryptoJS.AES.encrypt(str, key, {
        mode: CryptoJS.mode.CBC,
        iv: iv,
        padding: CryptoJS.pad.Pkcs7,
    })

    return encryptedValue.toString()
}
